package com.lul15834.orderfood.activity.user.fragment;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.lul15834.orderfood.MainActivity;
import com.lul15834.orderfood.R;
import com.lul15834.orderfood.activity.manager.UpdateMes;
import com.lul15834.orderfood.activity.manager.UpdatePwd;
import com.lul15834.orderfood.activity.user.ManageUser;
import com.lul15834.orderfood.activity.user.UserAddress;
import com.lul15834.orderfood.activity.user.UserUpdateMes;
import com.lul15834.orderfood.activity.user.UserUpdatePwd;
import com.lul15834.orderfood.bean.UserComBean;
import com.lul15834.orderfood.dao.AdminDao;
import com.lul15834.orderfood.until.Tools;


public class UserMyFragment extends Fragment {
    View rootview;//根视图

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootview=inflater.inflate(R.layout.fragment_user_my, container, false);
        //第一步实现，管理员信息的加载，信息的加载就必须有一个账号
        String account=Tools.getOnAccount(getContext());
        //查询这个账号的相关信息
        UserComBean user=AdminDao.getComUser(account);
        ImageView img=rootview.findViewById(R.id.user_my_img);//头像
        Bitmap bitmap=BitmapFactory.decodeFile(user.getsImg());
        img.setImageBitmap(bitmap);
        TextView Account=rootview.findViewById(R.id.user_my_account);//账号
        Account.setText("账号:"+account);
        TextView name=rootview.findViewById(R.id.user_my_name);//名字
        name.setText(user.getsName());
        TextView des=rootview.findViewById(R.id.user_my_address);//地址
        des.setText("住址:"+user.getsAddress());
        TextView phone=rootview.findViewById(R.id.user_my_phone);//地址
        phone.setText("联系方式:"+user.getsPhone());
        TextView sex=rootview.findViewById(R.id.user_my_sex);//地址
        sex.setText("性别:"+user.getsSex());
        ManageUser activity=(ManageUser)getActivity();
        //查看完成订单
        ManageUser man=(ManageUser) getActivity();
        TextView order=rootview.findViewById(R.id.user_my_order);//订单
        order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                man.showOrder();
            }
        });
        //查看完成订单
        TextView address=rootview.findViewById(R.id.user_my_addressMan);//订单
        address.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), UserAddress.class);
                startActivity(intent);
            }
        });
        //修改店铺信息
        TextView changeMes=rootview.findViewById(R.id.user_my_changeMes);//账号
        changeMes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), UserUpdateMes.class);
                startActivity(intent);
            }
        });
        //修改密码
        TextView changePwd=rootview.findViewById(R.id.user_my_changePwd);//密码
        changePwd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), UserUpdatePwd.class);
                startActivity(intent);
            }
        });
        //注销
        TextView zx=rootview.findViewById(R.id.user_my_zx);
        zx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), MainActivity.class);
                startActivity(intent);
            }
        });
        //退出系统
        TextView exit=rootview.findViewById(R.id.user_my_exit);
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finishAffinity();
            }
        });

        return rootview;
    }


}